package edu.ustb.services.weatherforecast.controller;

import edu.ustb.services.weatherforecast.service.WeatherForecastService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@CrossOrigin
@Api(tags = "天气查询接口")
@RestController
@RequestMapping("/api/v1/weather")
public class WeatherForecastController {

    @Autowired
    private WeatherForecastService weatherForecastService;

    @Autowired
    private EurekaAutoServiceRegistration eurekaAutoServiceRegistration;

    @ApiOperation("天气查询")
    @GetMapping("/forecast")
    public Map<String,Object> queryWeather(String location, String time) {
        return weatherForecastService.getCityWeather(location, time);
    }

    @ApiOperation("主动下线")
    @GetMapping("/offline")
    public void offLine() {
        eurekaAutoServiceRegistration.stop();
    }

    @ApiOperation("重新上线")
    @GetMapping("/reonline")
    public void reOnline() {
        eurekaAutoServiceRegistration.start();
    }
}
